﻿<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Sango Bang</title>
    <style type="text/css">
        .text { font: 8pt Trebuchet MS }
        
        body 
        { 
        	font: 11pt Trebuchet MS;
            padding-top: 72px;
            text-align: center;
             
        }
    </style>
    <script type="text/javascript" src="./js/xmlhelper.js" ></script>
    <script type="text/javascript" src="./js/message.js" ></script>
    <script type="text/javascript">
    var SilverlightControl;
    
    function pluginLoaded(sender){         
       SilverlightControl  = sender.get_element();
    }
    
    function ErrorAlert(args)
    {
        alert(args.toString());
    }
    
    function SucceedJoined(args)
    {
        document.getElementById("LeaveButton").disabled = "";
        MessageController.guid = args;
        Service.GetMsg(MessageController.guid, MessageController._OnGetMsgComplete);
    }

    function SendMessage(args)
    {
        MessageController.SendMsg(args);
    }

    function OnRequestCompleteGet(result)
    {
        SilverlightControl.Content.SendMessage.GetMessageFromServer(result);
    }
    
    function RegisterClick()
    {
        var yourname = document.getElementById("DisplayName");
        if (yourname.value == "")
        {
            alert("Please input your name first");
            return ;
        }
        MessageController.OnRecvMsg = OnRequestCompleteGet;
        MessageController.Join("<message type=\"newuser\"><user>"+yourname.value +"</user></message>");
    }
    function LeaveButton_onclick() 
    {
        if(confirm("Are you sure to leave?"))
        {
            MessageController.SendMsg("<message type=\"userLeave\"/>");
        }
    }
    

    </script>

</head>
<body >
    <form id="Form1" runat="server">
        <div style="text-align: left; left:100px; width: 600px; height:auto;margin:auto;">
            Your Display Name:
            <input id="DisplayName" type="text" />
            <input id="RegisterButton" type="button" value="Register" onclick="RegisterClick()" />
            <input id="LeaveButton" type="button" value="Leave" 
                onclick="LeaveButton_onclick()" disabled="disabled" />
	    </div>
        
        <div><asp:Image ID="URLString" style="visibility:collapse" Width="0" Height="0" runat="server" /></div>
    
        <asp:ScriptManager runat="server" ID="scriptManager">
            <Services>
                <asp:ServiceReference path="~/Service.asmx" />
            </Services>
        </asp:ScriptManager>
        <div  style="height:100%;">
            <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SangoClient.xap" Version="2.0" Width="950px" Height="600px"
             OnPluginLoaded="pluginLoaded"/>
        </div>
    </form>

</body>
</html>
